﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;
using BOHVote.Entity;
 

namespace BOH.AccreditationSystem
{
    public partial class Evaluate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //SetApplyEvaluation();
                string ApplyID = string.Empty;
                if (Request.QueryString["ID"] != null)
                {
                    ApplyID = Request.QueryString["ID"].ToString();
                    getApplyInfo(ApplyID);
                }
            }
        }

        protected void getApplyInfo(string ApplyID)
        {
            DataSet dst = ApplyClass.getApplyEvaluationByApplyID(ApplyID);
            if (dst.Tables[0].Rows.Count > 0)
            {
                labApplyName.Text = dst.Tables[0].Rows[0]["Apply_Name"].ToString();
                labIDCard.Text = dst.Tables[0].Rows[0]["IDCard"].ToString();
                drpEvaluation.SelectedValue = dst.Tables[0].Rows[0]["EvaluationResult"].ToString();
                txtRemark.Text = dst.Tables[0].Rows[0]["Remark"].ToString();
            }
        }

        protected void SetApplyEvaluation()
        {
            drpEvaluation.Items.Clear();
            DataSet dst = OtherClass.dstGetApplyEvaluation();
            foreach (DataRow dr in dst.Tables[0].Rows)
            {
                ListItem lit = new ListItem(dr["dict_display"].ToString(), dr["dict_value"].ToString());
                drpEvaluation.Items.Add(lit);
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null)
            {
                if (drpEvaluation.SelectedValue.ToUpper() == "N")
                {
                    ApplyClass.DeleteApplyEvaluaton(Request.QueryString["ID"].ToString(), ((BHUser)Session["user"]).UserID);
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script>AlertDataSave('EvaluateApply.aspx');</script>");
                }
                else
                {
                    ApplyClass.SaveApplyEvaluation(Request.QueryString["ID"].ToString(), drpEvaluation.SelectedValue, txtRemark.Text, ((BHUser)Session["user"]).UserID);
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script>AlertDataSave('EvaluateApply.aspx');</script>");
                }
                
            }
            
        }
    }
}
